﻿#include "json_data.h"
#pragma once
#include "json_trans.h"
#include "systemcfg_data.h"

/******************通信配置*****************/
RobotSetting TransFromRobotJ(const RobotJ& in)
{
	RobotSetting out = {};
	out.id = in.id();
	out.brand = in.brand();
	out.cmdPort = in.cmdPort();
	out.ip = in.ip();
	out.statePort = in.statePort();
	out.origin.TransFromPositonJ(in.origin());
	return out;
}
/*wcs 通信配置*/

WCSSetting TransFromWCScfgJ(const WCSCfgJ& in)
{
	WCSSetting out = {};
	out.type = in.type();
	out.robIP = in.robIP();
	out.robPort = in.robPort();
	out.wcsIP = in.wcsIP();
	out.wcsport = in.wcsPort();
	return out;
}


/***********************************点位配置**************************************/

JigSetting TransFormJigCfg(const JigCfg& in)
{
	JigSetting out = {};
	out.id = in.id();
	out.type = in.type();
	out.size.TransFromSizeJ(in.size());
	out.rob.TransFromPositonJ(in.rob());
	return out;
}
UnstackAlgSetting TransFromUnstackAlgCfg(const UnstackAlgCfg& in)
{
	UnstackAlgSetting out = {};
	out.calibration = in.calibration();
	out.jig = TransFormJigCfg(in.jig());
	out.dirX = in.dirX();
	out.dirY = in.dirX();
	out.maxSku.TransFromSizeJ(in.maxSku());
	out.minSku.TransFromSizeJ(in.minSku());
	out.sizeCheck = in.sizeCheck() == 1 ? true : false;
	out.maxnum = in.maxnum();
	return out;
}

/*码垛托盘配置*/
StackPlateSetting TransFormStackPlateCfg(const StackPlateCfg& in)
{
	StackPlateSetting out = {};
	out.id = in.id();
	out.di = in.di();
	out.dirEven = in.dirEven();
	out.dirOdd = in.dirOdd();
	out.base.TransFromPositonJ(in.base());
	out.alg = in.alg();
	out.maxsize.TransFromSizeJ(in.maxsize());
	return out;
}

/*拆垛托盘配置*/
UnstackPlateSetting TransFormUnstackPlateCfg(const UnstackPlateCfg& in)
{
	UnstackPlateSetting out = {};
	out.id = in.id();
	out.camera = in.camera();
	out.dir = in.dir();
	out.max = in.max();
	return out;
}

/*输送线点位配置*/
BoxlineSetting TransFromBoxlineCfg(const BoxlineCfg& in)
{
	BoxlineSetting out = {};
	out.id = in.id();
	out.type = in.type();
	out.posid = in.posid();
	out.alg = in.alg();
	out.dir = in.dir();
	out.base.TransFromPositonJ(in.base());
	if (in.di().isEmpty()) {
		return out;
	}
	QStringList dis = in.di().split(",");
	QStringList vals = in.dival().split(",");

	for (auto& iter : dis) {
		out.di.push_back(iter.toInt());	
	}
	for (auto& iter : vals) {
		out.dival.push_back(iter);
	}

	return out;
}



/************************安全配置*******************************/
InputWare TransFromInput(const Input& in)
{
	InputWare out = {};
	out.name = in.name();
	out.di = in.di();
	out.val = in.val();
	return out;
}
OutputWare TransFromOutput(const Output& in)
{
	OutputWare out = {};
	out.name = in.name();
	out.dox = in.doindex();
	out.val = in.val();
	return out;
}
SafedoorSetting TransFromSafeDoorJ(const SafeDoorJ& in)
{
	SafedoorSetting out = {};
	out.enable = in.enable() == 1 ? true : false;
	out.enter = in.enter();
	out.reset = in.reset();
	out.start = in.start();
	out.stop = in.stop();
	return out;
}

GratingSetting TransFromGratingJ(const GratingJ& in)
{
	GratingSetting out = {};
	out.enable = in.enable() == 1 ? true : false;
	out.id = in.id();
	out.trig = in.trig();
	out.fault = in.fault();
	return out;
}

AlarmSetting TransFromAlarmJ(const AlarmJ& in)
{
	AlarmSetting out = {};
	out.enable = in.enable() == 1 ? true : false;
	out.red = in.red();
	out.green = in.green();
	out.yellow = in.yellow();
	return out;
}

SafeLockSetting TransFromSafeLockJ(const SafeLockJ& in)
{
	SafeLockSetting out = {};
	out.enable = in.enable() == 1 ? true : false;
	out.state = in.state();
	out.set = in.set();
	return out;
}

/**********************业务线配置*****************************/
RelativePoint TransFormRelativePointCfg(const RelativePointCfg& in)
{
	RelativePoint out = {};
	out.diff.TransFromPositonJ(in.diff());
	out.relateNum = in.relateNum();
	out.fix_a = in.fix_a();
	out.fix_b = in.fix_b();
	out.fix_c = in.fix_c();
	out.fix_x = in.fix_x();
	out.fix_y = in.fix_y();
	out.fix_z = in.fix_z();
	return out;
}
LocationPoint TransFromLocationPointCfg(const LocationPointCfg& in)
{
	LocationPoint out = {};
	out.type = in.type();
	out.id = in.id();

	return out;
}
PointAction TransFormPointActionCfg(const PointActionCfg& in)
{
	PointAction out = {};
	out.type = (PiontActionType)in.type();
	out.param = in.param();

	return out;
}
PathPointSetting TransFromPathPointCfg(const PathPointCfg& in)
{
	PathPointSetting out = {};
	out.id = in.pointId();
	out.name = in.name();
	out.type = in.pointType();
	out.acc = in.acc();
	out.vel = in.vel();
	out.stop = in.stop();
	out.zone = in.zone();
	out.math = (PathPointMathType)in.mathType();
	out.fix.TransFromPositonJ(in.fix());
	out.location = TransFromLocationPointCfg(in.location());
	out.action = TransFormPointActionCfg(in.action());
	out.relate = TransFormRelativePointCfg(in.relate());
	return out;
}


PathSetting TransFromPathCfg(const PathCfg& in)
{
	PathSetting out = {};
	out.id = in.id();
	out.name = in.name();
	for (auto& iter : in.points()) {
		out.points.append(TransFromPathPointCfg(iter));
	}

	return out;
}

PipelineSetting TransFormPipelineCfg(const PipelineCfg& in)
{
	PipelineSetting out = {};
	out.id = in.id();
	out.type = in.type();
	out.rob = in.rob();
	out.strat = in.start();
	out.end = in.end();
	for (auto& iter : in.paths()) {
		PathSetting temp = TransFromPathCfg(iter);
		out.paths.append(temp);
	}
	return out;
}
